<%@tag pageEncoding="UTF-8"%>
<%@ attribute name="page" type="com.apexedu.framework.util.Pager" required="true"%>
<%@ attribute name="paginationSize" type="java.lang.Integer" required="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
int current =  page.getCurrentPageno();
int begin = Math.max(1, current - paginationSize/2);
int end = Math.max(1,(int)page.getTotalRows()/page.getEachPageRows());
if(page.getTotalRows()%page.getEachPageRows()!=0)
	end = Math.max(1,(int)page.getTotalRows()/page.getEachPageRows()+1);

request.setAttribute("current", current);
request.setAttribute("begin", begin);
request.setAttribute("end", end);
%>

<script type="text/javascript">
	var currentPageno = $('#yspager_currentPageno').val();
	function trunPage(currentNo) {
		$('#yspager_currentPageno').val(currentNo);
		document.forms['ysform'].submit();
	}
</script>

<div class="pagination" >
	<ul style="float: left;">
		 <% if (current != 1){%>
               	<li><a onclick="trunPage(1)"><i class="icon-double-angle-left"></i></a></li>
                <li><a onclick="trunPage(<%=current-1 %>)"><i class="icon-angle-left"></i></a></li>
         <%}else{%>
                <li class="disabled"><a ><i class="icon-double-angle-left"></i></a></li>
                <li class="disabled"><a ><i class="icon-angle-left"></i></a></li>
         <%} %>
 
        
        <%
        	if (end <= 8 || current<=2) {
        		for (int i=begin; i<=(end>8?8:end); i++) {
        			if (i == current) {
         %>
	                    <li class="active"><a onclick="trunPage(<%=i %>)"><%=i %></a></li>
	     <%	
	     			} else {
	      %>
	                    <li><a onclick="trunPage(<%=i %>)"><%=i %></a></li>
	      <%
	      			}
	      		}
	       %>
         <%} else if (current > 2){
         		for (int i=current-2; i<=((current + 5>end)?end:(current + 5)); i++) {
         %>
         <%
         	        			if (i == current) {
         %>
	                    <li class="active"><a onclick="trunPage(<%=i %>)"><%=i %></a></li>
	     <%	
	     			} else {
	      %>
	                    <li><a onclick="trunPage(<%=i %>)"><%=i %></a></li>
         <%}
         }
         } %>
	  
	  	 <% if (current != end){%>
               	<li><a onclick="trunPage(<%=current+1 %>)"><i class="icon-angle-right"></i></a></li>
                <li><a onclick="trunPage(<%=end %>)"><i class="icon-double-angle-right"></i></a></li>
         <%}else{%>
                <li class="disabled"><a ><i class="icon-angle-right"></i></a></li>
                <li class="disabled"><a ><i class="icon-double-angle-right"></i></a></li>
         <%} %>

	</ul>
	<span style="float: left;font-weight: bold;">共查询<%=end %>页，数据<%=page.getTotalRows() %>条</span>
</div>

<style>
	.pagination li{
		cursor: pointer;
	}
</style>

